package com.weijianhuawen.wjblog.admin.controller;

import com.weijianhuawen.wjblog.admin.mode.vo.wiki.*;
import com.weijianhuawen.wjblog.admin.service.AdminWikiService;
import com.weijianhuawen.wjblog.common.aspect.ApiOperationLog;
import com.weijianhuawen.wjblog.common.utils.PageResponse;
import com.weijianhuawen.wjblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description:
 * @date: 2024-11-11 13:38
 */

@RestController
@RequestMapping("/admin/wiki")
@Api(tags = "后台知识库模块")
public class AdminWikiController {
    @Autowired
    private AdminWikiService wikiService;
    @PostMapping("/add")
    @ApiOperation(value = "新增知识库详情")
    @ApiOperationLog(description = "新增知识库详情")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response addWiki(@RequestBody @Validated AddWikiReqVo vo) {
        return wikiService.addWiki(vo);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除知识库")
    @ApiOperationLog(description = "根据知识库机id删除id")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response deleteWiki(@RequestBody @Validated DeleteWikiReqVo vo) {
        return wikiService.deleteWiki(vo);
    }

    @PostMapping("/page/list")
    @ApiOperation(value = "知识库后台管理分页查询")
    @ApiOperationLog(description = "知识库后台管理分页查询")
    public PageResponse findWikiPageList(@RequestBody @Validated FindWikiPageListReqVo vo) {
        return wikiService.findWikiPageList(vo);
    }

    @PostMapping("/one")
    @ApiOperation(value = "知识库单数据查询")
    @ApiOperationLog(description = "通过id查询知识库")
    public Response findWikiPageList(@RequestBody @Validated FindOneWikiReqVo vo) {
        return wikiService.findOneWiki(vo);
    }

    @PostMapping("/isTop/update")
    @ApiOperation(value = "知识库置顶")
    @ApiOperationLog(description = "知识库置顶更新")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateWikiIsTop(@RequestBody @Validated UpdateWikiIsTopReqVo vo) {
        return wikiService.updateWikiIsTop(vo);
    }

    @PostMapping("/isPublish/update")
    @ApiOperation(value = "更新知识库发布状态")
    @ApiOperationLog(description = "更新知识库发布状态")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateWikiIsPublish(@RequestBody @Validated UpdateWikiIsPublishReqVo vo) {
        return wikiService.updateWikiIsPublish(vo);
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新知识库")
    @ApiOperationLog(description = "更新知识库")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateWiki(@RequestBody @Validated UpdateWikiReqVo vo) {
        return wikiService.updateWiki(vo);
    }

    @PostMapping("/catalog/list")
    @ApiOperation(value = "获取知识库所绑定的目录列表")
    @ApiOperationLog(description = "获取知识库id所对应的目录列表")
    public Response findCatalogList(@RequestBody @Validated FindWikiCatalogListReqVo vo) {
        return wikiService.findWikiCatelogList(vo);
    }

    @PostMapping("/catalog/update")
    @ApiOperation(value = "更新知识库目录")
    @ApiOperationLog(description = "更新知识库目录")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateWikiCatalogs(@RequestBody @Validated UpdateWikiCatalogReqVo vo) {
        return wikiService.updateWikiCatalogs(vo);
    }
}
